module("TopPanel", package.seeall )

FONT = "TimeLeftFont"

surface.CreateFont("CenterPrintText",28,125,true,false, FONT)

do
	local PANEL = {}
	PANEL.Offset = 0

	function PANEL:Init()
		self.NextThink = 0
	end

	function PANEL:GetText()
		return "0"
	end

	function PANEL:Think()
		if CurTime() > self.NextThink then
			self:InvalidateLayout()
			self.NextThink = CurTime() + 1.0
		end
	end
	
	function PANEL:GetColor()
		return Color(255,255,255,255)
	end

	function PANEL:Paint()
		draw.RoundedBox( 16, 0, -16, self:GetWide(), self:GetTall() + 16, Color( 0, 0, 0, 100) )
		draw.SimpleText(self:GetText(), FONT, self:GetWide() / 2, self:GetTall() / 2, self:GetColor(), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
	end
	
	function PANEL:SetOffset( offset )
		self.Offset = offset
	end

	function PANEL:PerformLayout()

		local Time = self:GetText()
		
		surface.SetFont( FONT )
		
		local wide, tall = surface.GetTextSize(Time)
		
		wide = math.max( 32, wide * 1.2 )
		
		self:SetSize( wide, tall + 15 )
		self:SetPos( self:GetParent():GetWide() * 0.5 + self.Offset, self.y )
		
	end

	vgui.Register("NCTopInfo", PANEL )
end


/* ==============================
	Top Panel info
   ============================ */
  
   
local PANEL = {}
function PANEL:GetText()
	local timeLeft = Game.TimeLeft()
	
	local Minutes = math.floor( timeLeft / 60 )
	local Seconds = math.floor( math.fmod( timeLeft, 60 ) )
	
	return string.rep( "0", math.max( 0, 2-string.len(Seconds)) ) .. Minutes .. ":" .. string.rep( "0", 2-string.len(Seconds) ) .. Seconds
end  
vgui.Register("NCTimeLeft", PANEL, "NCTopInfo" )


/* ==============================
	Team score info
   ============================ */
  
   
local PANEL = {}
function PANEL:GetText()
	return team.GetScore( self.Team )
end  

function PANEL:SetTeam( TeamId )
	self.Team = TeamId
end

function PANEL:GetColor()
	return team.GetColor( self.Team )
end
vgui.Register("NCTeamScore", PANEL, "NCTopInfo" )



/* ==============================
	Show block info
   ============================ */
  
   
local PANEL = {}

function PANEL:PerformLayout()
	if ValidEntity( LocalPlayer() ) then
		local ReturnStr = Block.BlockCount( LocalPlayer():Team() ) .. "/" .. Block.MaxLimit()
		
		self.GetText = function()
			return ReturnStr
		end
	end

	self.BaseClass.PerformLayout( self )
end
vgui.Register("NCBlockCount", PANEL, "NCTopInfo" )

/* ==============================
	Game rounds
   ============================ */

   
local PANEL = {}

function PANEL:GetText()
	return Game.Round() .. "/" .. Game.MaxRound()
end 
vgui.Register("NCRoundsLeft", PANEL, "NCTopInfo" )